<template>
  <div id="main">
    <viedobg></viedobg>
    <div class="page-title">高平市水环境监控预警与风险防控管理平台</div>
    <div class="d-flex a-center j-center" style="height: calc(100% - 65px);">
        <div class="menu-box">
          <systems :menuList="menuList" @menuClicked="menuClickEvent($event)"></systems>
        </div>
    </div>
    <div class="right-menu">
      <el-dropdown  class="avatar-container right-menu-item hover-effect" trigger="hover">
        <div class="avatar-wrapper">
          <img src="../../assets/menu/exit.png" class="user-avatar" />
          <span class="user-nickname"> {{ nickName }} </span>
        </div>
        <el-dropdown-menu slot="dropdown">
          <router-link to="/user/profile">
            <el-dropdown-item>个人中心</el-dropdown-item>
          </router-link>
          <el-dropdown-item divided @click.native="logout">
            <span>退出登录</span>
          </el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>

    <!-- <div class="header">
      <h3 class="titles">高平市水环境监控预警与风险防控管理平台</h3>
      <div class="right-menu">
        <el-dropdown
          class="avatar-container right-menu-item hover-effect"
          trigger="hover"
        >
          <div class="avatar-wrapper">
            <img :src="avatar" class="user-avatar" />
            <span class="user-nickname"> {{ nickName }} </span>
          </div>
          <el-dropdown-menu slot="dropdown">
            <router-link to="/user/profile">
              <el-dropdown-item>个人中心</el-dropdown-item>
            </router-link>
            <el-dropdown-item divided @click.native="logout">
              <span>退出登录</span>
            </el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </div>
    <div class="rightpart">
      <div></div>
      <div></div>
    </div>

    <ul class="bot">
      <li
        v-for="(item, index) in menuList"
        :key="item.keyId"
        @click="menuClickEvent(item)"
      >
        <div class="bottop" :class="`bottop${(index % 6) + 1}`">
          {{ item.menuName }}{{index}}
        </div>
      </li>
    </ul> -->
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import { getMenuList } from "@/api/commonApi";
import { getRouterNew } from "@/api/commonApi";
import viedobg from "../../components/viewComponents/videobg/viedobg.vue";
import systems from './systems.vue'
export default {
  components: {
    viedobg,
    systems
  },
  data() {
    return {
      menuList: [],
    };
  },
  computed: {
    ...mapGetters(["avatar", "nickName"]),
  },
  methods: {
    getMenuList() {
      getMenuList().then((res) => {
        console.log(">>>", res);

        this.menuList = res.data;
      });
    },
    // 核心：递归拼接完整链接
    getFullLink(node) {
      // 处理当前节点path：去除开头的"/"，避免拼接出"//"；若path不存在则用空字符串
      const currentPath = node.path ? node.path.replace(/^\/+/, "") : "";

      // 判断是否有子节点（必须是非空数组）
      if (Array.isArray(node.children) && node.children.length > 0) {
        // 取第一个子节点继续递归，拼接子节点路径
        const firstChildLink = this.getFullLink(node.children[0]);
        // 子节点路径非空时才加"/"，避免结尾多斜杠
        return firstChildLink
          ? `${currentPath}/${firstChildLink}`
          : currentPath;
      }

      // 没有子节点，返回当前节点路径（递归终止）
      return currentPath;
    },
    menuClickEvent(e) {
      this.$store.commit("SET_SYSID", e.keyId);
      this.$store.dispatch("GenerateRoutes").then(() => {
        getRouterNew(e.keyId).then((res) => {
          console.log(">>>luyou", res);
          // let path = res.data[0].path;
          let path = res.data.map((node) => this.getFullLink(node));
          console.log(">>>pathssssssss", path);
          let gopath = "";
          if (path.length > 0) {
            gopath = path[0];
            setTimeout(() => {
              // this.$router.push({
              //   path: path,
              // });
              window.open(gopath, "_blank");
            }, 1000);
          } else {
            this.$message.warn("暂无数据");
          }
        });
      });
    },
    logout() {
      this.$confirm("确定注销并退出系统吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$store.dispatch("LogOut").then(() => {
            location.href = "/login";
          });
        })
        .catch(() => {});
    },
  },
  mounted() {
    this.$store.dispatch("GetInfo");
    this.getMenuList();
  },
};
</script>

<style lang="scss" scoped>
.panel {
  width: 100%;
  height: 100%;
  overflow: hidden;
  box-sizing: border-box;
}
#main {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  position: relative;
  background-image: url('../../assets/login/bg.png') ;
  // background-image: url(~@/assets/img/2bg.png);
  background-size: 100% 100%;
  /* background-repeat: no-repeat; */
  .page-title{
    text-align: center ;
    font-weight: bold;
    font-size: 30px;
    color: #FFFFFF;
    line-height: 60px;
    text-shadow: 0px 4px 1px rgba(19,80,143,0.66);
  }
  .menu-box{
    width: 1500px;
    height: 550px;
    background-image: url('../../assets/menu/k1.png');
    background-size: 100% 100%;
    position: relative;
  }
  .right-menu {
    position: absolute;
    right: 35px;
    top: 35px;
    z-index: 2;
    height: 50px;
    line-height: 50px;
    margin-right: 30px;

    &:focus {
      outline: none;
    }

    .right-menu-item {
      display: inline-block;
      padding: 0 8px;
      height: 100%;
      font-size: 18px;
      color: #5a5e66;
      vertical-align: text-bottom;

      &.hover-effect {
        cursor: pointer;
        transition: background 0.3s;

        &:hover {
          background: rgba(0, 0, 0, 0.025);
        }
      }
    }

    .avatar-container {
      margin-right: 0px;
      padding-right: 0px;

      .avatar-wrapper {
        margin-top: 10px;
        position: relative;

        .user-avatar {
         
          cursor: pointer;
          width: 30px;
          height: 30px;
          border-radius: 50%;
        }

        .user-nickname {
          position: relative;
          color: #73B6EF;
          bottom: 10px;
          font-size: 14px;
          font-weight: bold;

        }

        .el-icon-caret-bottom {
          cursor: pointer;
          position: absolute;
          right: -20px;
          top: 25px;
          font-size: 12px;
        }
      }
    }
  }
}

a {
  /* color: #00D8FF; */
  color: #5793c8;
  font-size: 1.7vh;
  text-decoration: none;
}

.header {
  // background-image: url(~@/assets/img/title.png);
  background-size: 25%;
  background-repeat: no-repeat;
  height: 10%;
  width: 100%;
  background-position: 3% 50%;
  .titles {
    margin: 0;
    padding: 30px;
    /* float: left; */
    font-size: 35px;
    color: #fff;
    font-weight: bold;
    letter-spacing: 3px;
    text-align: center;
    left: 50%;
    position: absolute;
    transform: translateX(-50%);
  }

}

/* 目录入口样式 */
.bot {
  height: 44%;
  width: 94%;
  margin-left: 3%;
  display: flex;
  justify-content: center;
  align-items: start;
  flex-wrap: wrap;
  position: relative;
  top: 14%;
}

.bot > li {
  width: 23%;
  height: 50%;
  position: relative;
  margin: 0 7px;
  list-style: none;
}

.bottop1 {
  background: url(~@/assets/img/logBtn/1bg.png) no-repeat;
}

.bottop2 {
  background: url(~@/assets/img/logBtn/2bg.png) no-repeat;
}

.bottop3 {
  background: url(~@/assets/img/logBtn/3bg.png) no-repeat;
}

.bottop4 {
  background: url(~@/assets/img/logBtn/4bg.png) no-repeat;
}

.bottop5 {
  background: url(~@/assets/img/logBtn/5bg.png) no-repeat;
}

.bottop6 {
  background: url(~@/assets/img/logBtn/6bg.png) no-repeat;
}

.bottop7 {
  background: url(~@/assets/img/icon6.png) no-repeat;
}

/* 闪烁 */
.sonImg {
  height: 20px;
  width: 50%;
  background: url(~@/assets/img/gx.png) no-repeat;
  background-size: 100% 100%;
  position: absolute;
  bottom: 2.5%;
  left: 25%;
  animation: flash 1s linear infinite;
}

@keyframes flash {
  /* form {
        opacity: 0;
    } */
  to {
    opacity: 0.5;
  }
}

.bottop {
  height: 70%;
  width: 100%;
  background-size: 86% 100%;
  background-position: center;
  font-size: 25px;
  font-weight: bold;
  color: #fff;
  padding: 30px 45px;
  cursor: pointer;
  text-align: center;
}

.rukou {
  height: 65%;
  width: 100%;
  background-image: url(~@/assets/img/dz.png);
  background-size: 100% 100%;
  padding-top: 5px;
}

.rukou > div {
  height: 15%;
  width: 100%;
}

.rukou > div a {
  display: flex;
  /* width: 100%; */
  height: 100%;
  justify-content: center;
  align-items: center;
  letter-spacing: 1px;
}

.rukou > div a:hover {
  font-size: 1.8vh;
  font-weight: bold;
  color: #00d8ff;
  border-bottom: 2px solid #00d8ff;
}

.rukou > div a:hover::before {
  content: "";
  display: block;
  width: 6px;
  height: 6px;
  background: #00d8ff;
  border-radius: 50%;
  margin-right: 6px;
}

.rukou > div a::before {
  content: "";
  display: block;
  width: 5px;
  height: 5px;
  background: #5793c8;
  border-radius: 50%;
  margin-right: 6px;
}

.rukou2 > div {
  display: flex;
  height: 13%;
  justify-content: space-around;
}

.rukou2 > div > div {
  width: 48%;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.textlong > div a {
  font-size: 1.2vh;
}

.jgpt1,
.jgpt2 {
  display: flex;
  justify-content: space-around;
}
</style>
